package com.example.musicwebcon.controller;

import com.example.musicwebcon.model.ResponseMessage;
import com.example.musicwebcon.model.dto.recentDTO;
import com.example.musicwebcon.model.recentSong;
import com.example.musicwebcon.service.serviceInterface.IrecentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/recent")
public class recentController {
    @Autowired
    IrecentService recentService;
    //增加
    @PostMapping
    public ResponseMessage add(@Validated @RequestBody recentDTO recentSong){
        recentSong song = recentService.add(recentSong);
        return ResponseMessage.success(song);
    }
    //查询
    @GetMapping("/{musicId}")
    public ResponseMessage get(@PathVariable String musicId){
        recentSong song = recentService.getMusicId(musicId);
        return ResponseMessage.success(song);
    }
    //查询所有
    @GetMapping
    public ResponseMessage getAll(){
        Iterable<recentSong> songs = recentService.getALl();
        return ResponseMessage.success(songs);
    }

    //修改
    @PutMapping
    public ResponseMessage edit(@Validated @RequestBody recentDTO recentSong){
        recentSong song = recentService.edit(recentSong);
        return ResponseMessage.success(song);
    }
    //删除
    @DeleteMapping("/{musicId}")
    public ResponseMessage delete(@PathVariable String musicId){
        recentService.deleteMusicId(musicId);
        return ResponseMessage.success(null);
    }
}
